﻿<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>

<!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
<div id="test" style="width: 600px;height:400px;"></div>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/echarts.js"></script>
<script type="text/javascript" src="https://cdn.goeasy.io/goeasy.js"></script>
<script type="text/javascript">
    // 1.基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('test'));
    var option = {
        title: {
            text: '用户男女比例'
        },
        tooltip: {},
        legend: {
            data:['人数']
        },
        xAxis: {
            data: ["男","女"]
        },
        yAxis: {},
        series: [{
            name: '人数',
            type: 'line',
            data: [5,10]
        }]
    };

    myChart.setOption(option);

    var goEasy = new GoEasy({
        appkey:"BC-2187d9de930847288eb36ed08caa274a"
    });
    goEasy.subscribe({
        channel:"my_channel",
        onMessage:function (message) {
            var count = JSON.parse(message.content)
            var option1 = {
                title: {
                    text: '用户男女比例'
                },
                tooltip: {},
                legend: {
                    data:['人数']
                },
                xAxis: {
                    data: ["男","女"]
                },
                yAxis: {},
                series: [{
                    name: '人数',
                    type: 'line',
                    data: count
                }]
            };

            myChart.setOption(option1);
        }
    });

</script>